package cn.skcks.listener;

import com.mysql.cj.jdbc.AbandonedConnectionCleanupThread;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import java.sql.Driver;
import java.sql.DriverManager;
import java.util.Enumeration;

public class DBCloseListener implements ServletContextListener {
	@Override
	public void contextInitialized(ServletContextEvent servletContextEvent) {

	}

	@Override
	public void contextDestroyed(ServletContextEvent servletContextEvent) {
		Enumeration<Driver> drivers = DriverManager.getDrivers();

		Driver driver;

		while (drivers.hasMoreElements()){
			try{
				driver = drivers.nextElement();
				DriverManager.deregisterDriver(driver);
			} catch (Exception ignored){}
		}
		AbandonedConnectionCleanupThread.checkedShutdown();
	}
}